package labox.innovation.loginserver.socket.serverpackets;

import labox.innovation.loginserver.socket.LoginClient;

/**
 * 在客户端创建完后服务器发给客户端的第一个初始化协议，内容_sessionId
 * 
 */
public final class Init extends LoginServerPacket {

	private int _sessionId;

	private byte[] _encryptKeys;

	public Init(LoginClient client) {
		this(client.getSessionId(), client.enableCrypt());
	}

	public Init(int sessionId, byte[] keys) {
		_sessionId = sessionId;//随机的session id
		_encryptKeys = keys;
	}

	/**
	 * @see com.l2jserver.mmocore.network.SendablePacket#write()
	 */
	@Override
	public void write() {
		writeByte(PTL_INIT); // init packet id
		writeInt(_sessionId); // session id
		writeByte(8);
		for (int i = -1; ++i < 8;) {
			writeByte(_encryptKeys[i]);
		}
	}
}
